package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/shop")
@Api(tags = "管理员店铺操作接口")
public class ShopController {
    private static final String KEY = "SHOP_STATUS";
    @Autowired
    private RedisUtil redisUtil;

    @ApiOperation("更改店铺营业状态")
    @PutMapping("/{status}")
    public Result<String> updateShopStatus(@PathVariable Integer status) {
        log.info("设置店铺状态为：{}",status == 1 ? "营业中" : "打样中");

        redisUtil.set(KEY,status);
        return Result.success();
    }

    @ApiOperation("获取店铺营业状态")
    @GetMapping("/status")
    public Result<Integer> getShopStatus(){
        Integer status = (Integer) redisUtil.get(KEY);
        log.info("获取店铺状态为：{}",status == 1 ? "营业中" : "打样中");
        return Result.success(status);
    }
}
